import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:transparent_image/transparent_image.dart';

class ImageLearn extends StatefulWidget {
  @override
  _ImageLearnState createState() => _ImageLearnState();
}

class _ImageLearnState extends State<ImageLearn> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('学习Image'),
      ),
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.all(5),
          child: Column(
            children: <Widget>[
              Text('加载本地资源文件'),
              Image.asset(
                'assets/images/login_bg.png',
                width: 120,
                height: 120,
              ),
              Text('加载网络图片'),
              Image.network(
                'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1573382487161&di=d13a9e60643eeef70bb8217c82b17ec8&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F96432744cb74196b13aae840d4ae2a01b4789e3b1d609-TFw4VA_fw658',
                width: 120,
                height: 120,
                fit: BoxFit.fill,
              ),
              Text('placeholder使用'),
              Stack(
                children: <Widget>[
                  Center(
                    child: CircularProgressIndicator(),
                  ),
                  Center(
                    child: FadeInImage.memoryNetwork(
                      placeholder: kTransparentImage,
                      image:
                          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1573382487161&di=d13a9e60643eeef70bb8217c82b17ec8&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F96432744cb74196b13aae840d4ae2a01b4789e3b1d609-TFw4VA_fw658',
                      width: 120,
                      height: 120,
                      fit: BoxFit.fill,
                    ),
                  )
                ],
              ),
              Text('placeholder使用本地图片'),
              Center(
                child: FadeInImage.assetNetwork(
                  placeholder: 'assets/images/login_bg.png',
                  image:
                      'http://b-ssl.duitang.com/uploads/item/201504/19/20150419H5539_KABWt.jpeg',
                  width: 120,
                  height: 120,
                  fit: BoxFit.fill,
                ),
              ),
              Text('使用图片缓存'),
              Center(
                child: CachedNetworkImage(
                  imageUrl:
                      "http://b-ssl.duitang.com/uploads/item/201504/19/20150419H5539_KABWt.jpeg",
                  placeholder: (context, url) => CircularProgressIndicator(),
                  errorWidget: (context, url, err) => Icon(Icons.error),
                  width: 120,
                  height: 120,
                  fit: BoxFit.fill,
                ),
              ),
              Text("Icon使用"),
              Icon(
                Icons.android,
                size: 50.0,
              )
            ],
          ),
        ),
      ),
    );
  }
}
